package com.kuqi.entity;


import net.minidev.json.JSONObject;

import javax.persistence.*;

@Entity
@Table(name = "chapters")
public class ChapterInfo {

    @Id // 指定主键
    private int id;

    @Column(name = "book_id")
    private int bookId;

    @Column(name = "chapter_name")
    private String chapterName;

    @Column(name = "chapter_content")
    private String chapterContent;

    @Column(name = "update_date")
    private String updateDate;

    @Column(name = "chapter_index")
    private int chapterIndex;

    //数据转为json字符串并返回
    public String toJsonString(){
        return this.toJsonObject().toJSONString();
    }

    //转为Object对象
    public JSONObject toJsonObject()
    {
        JSONObject result = new JSONObject();
        result.put("id", id);
        result.put("bookId", bookId);
        result.put("chapterName", chapterName);
        result.put("chapterContent", chapterContent);
        result.put("updateDate", updateDate);
        result.put("chapterIndex", chapterIndex);
        return result;
    }

    public ChapterInfo(){}

    public ChapterInfo(int id, int bookId, String chapterName, String chapterContent, String updateDate, int chapterIndex) {
        this.id = id;
        this.bookId = bookId;
        this.chapterName = chapterName;
        this.chapterContent = chapterContent;
        this.updateDate = updateDate;
        this.chapterIndex = chapterIndex;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public int getBookId() {
        return bookId;
    }

    public void setBookId(int bookId) {
        this.bookId = bookId;
    }

    public String getChapterName() {
        return chapterName;
    }

    public void setChapterName(String chapterName) {
        this.chapterName = chapterName;
    }

    public String getChapterContent() {
        return chapterContent;
    }

    public void setChapterContent(String chapterContent) {
        this.chapterContent = chapterContent;
    }

    public String getUpdateDate() {
        return updateDate;
    }

    public void setUpdateDate(String updateDate) {
        this.updateDate = updateDate;
    }

    public int getChapterIndex() {
        return chapterIndex;
    }

    public void setChapterIndex(int chapterIndex) {
        this.chapterIndex = chapterIndex;
    }
}